﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using MalRec.Base;
using MalRec.Base.Inteface.Service;
using MalRec.Base.Service;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using MyAnimelistRecommender.wAnime.Configuration;

namespace MyAnimelistRecommender.wAnime.View
{
    public class ModulePresenter : IModulePresenter
    {
        #region private member

        private readonly ApplicationService _appService;

        private DelegateCommand<object> _TestCommand;

        #endregion private member

        #region public member

        #endregion public member

        #region constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ModulePresenter"/> class
        /// </summary>
        /// <param name="view">the used view</param>
        /// <param name="appService">the application service</param>
        public ModulePresenter(IModuleView view, ApplicationService appService, IEventAggregator eventAggregator)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            if (appService == null)
            {
                throw new ArgumentNullException("appService");
            }

            View = view;
            View.Presenter = this;

            _appService = appService;

            RegisterCommands();

            View.Model.Configuration = appService.GetConfigurationObject<wAnimeConfiguration>();

            //View.Model.PropertyChanged += OnModelPropertyChanged;

            //eventAggregator.GetEvent<ApplicationEvent>().Subscribe(OnModuleMallChanged);
        }

        #endregion constructors

        #region private methods

        private void RegisterCommands()
        {
            _TestCommand = new DelegateCommand<object>(ExecuteTestCommand, CanExecuteTestCommand);
            wAnimeCommands.TestCommand.RegisterCommand(_TestCommand);
        }

        private void ExecuteTestCommand(object param)
        {
            MessageBox.Show((param ?? "").ToString());
        }

        private bool CanExecuteTestCommand(object param)
        {
            return true;
        }

        private void ExecuteCancelCommand(object param)
        {
            GlobalCommands.CloseModuleCommand.Execute(wAnimeModule.StaticModuleName);
        }

        private bool CanExecuteCancelCommand(object param)
        {
            return true;
        }

        #endregion private methods

        #region protected methods

        #endregion protected methods

        #region public methods

        #endregion public methods

        #region IPresenter<IwAnimeView> Members

        public IModuleView View
        {
            get;
            private set;
        }

        #endregion IPresenter<IwAnimeView> Members
    }
}